package com.right.health.app.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.right.health.app.able.INameAble;

import java.util.List;

/*
 * Created by hopeliao on 2019-11-24
 *
 */
public class FamilyResponse extends PageResponse {

    public List<FamilyInfo> members;

    public static class FamilyInfo implements Parcelable, INameAble {

        @Override
        public String getName() {
            return shipName;
        }

        public String membership;
        public String shipName;
        public String membername;
        public String sex;
        public String memberidcard;
        public String memberphone;
        public String personid;
        public String createtime;
        public String memberid;
        public String updatetime;
        public String showCardNo;
        public String healthcardno;
        public String patientidcardnum;

        public String getShowCardNo() {
            if(TextUtils.isEmpty(showCardNo) && !TextUtils.isEmpty(memberidcard)) {
                StringBuilder sb = new StringBuilder();
                String frist = memberidcard.substring(0, 1);
                String last = memberidcard.substring(memberidcard.length()- 1);
                sb.append(frist);

                for (int i = 0; i < memberidcard.length() - 2; i++) {
                    sb.append("*");
                }
                sb.append(last);

                showCardNo = sb.toString();
            }
            if(TextUtils.isEmpty(showCardNo)) {
                return memberidcard;
            }
            return showCardNo;
        }

        public FamilyInfo(String ship, String name) {
            this.membership = ship;
            this.shipName = name;
        }

        public FamilyInfo() {
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(this.membership);
            dest.writeString(this.shipName);
            dest.writeString(this.membername);
            dest.writeString(this.sex);
            dest.writeString(this.memberidcard);
            dest.writeString(this.memberphone);
            dest.writeString(this.personid);
            dest.writeString(this.createtime);
            dest.writeString(this.memberid);
            dest.writeString(this.updatetime);
            dest.writeString(this.showCardNo);
            dest.writeString(this.healthcardno);
            dest.writeString(this.patientidcardnum);
        }

        protected FamilyInfo(Parcel in) {
            this.membership = in.readString();
            this.shipName = in.readString();
            this.membername = in.readString();
            this.sex = in.readString();
            this.memberidcard = in.readString();
            this.memberphone = in.readString();
            this.personid = in.readString();
            this.createtime = in.readString();
            this.memberid = in.readString();
            this.updatetime = in.readString();
            this.showCardNo = in.readString();
            this.healthcardno = in.readString();
            this.patientidcardnum = in.readString();
        }

        public static final Creator<FamilyInfo> CREATOR = new Creator<FamilyInfo>() {
            @Override
            public FamilyInfo createFromParcel(Parcel source) {
                return new FamilyInfo(source);
            }

            @Override
            public FamilyInfo[] newArray(int size) {
                return new FamilyInfo[size];
            }
        };
    }

}
